package com.usian.wemedia.controller.v1;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.apis.media.WmUserControllerApis;
import com.usian.model.media.pojos.WmUser;
import com.usian.wemedia.service.WmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/wmuser")
public class WmUserController implements WmUserControllerApis {

    @Autowired
    private WmUserService wmUserServiceI;

    @Override
    @GetMapping("findbyname/{name}")
    public WmUser queryWmUserByName(@PathVariable String name) {
        LambdaQueryWrapper<WmUser> userLambdaQueryWrapper =
                Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName, name);
        List<WmUser> wmUserList = wmUserServiceI.list(userLambdaQueryWrapper);
        if (null != wmUserList && !wmUserList.isEmpty()) {
            return wmUserList.get(0);
        }
        return null;
    }

    @Override
    @PostMapping("save")
    public boolean saveWmUser(@RequestBody WmUser wmUser) {
        return wmUserServiceI.save(wmUser);
    }

    @GetMapping("findUserById/{id}")
    @Override
    public WmUser findUserById(@PathVariable Integer id){
        return wmUserServiceI.getById(id);
    }
}
